package com.cloud.pole.recharge.service.impl;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.codec.binary.StringUtils;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.util.HttpClientUtils;
import com.cloud.pole.common.util.OrderNoUtils;
import com.cloud.pole.recharge.constant.RechargeConstant;
import com.cloud.pole.recharge.model.BankRecvFeeOutRsp;
import com.cloud.pole.recharge.model.BuildSeqRsp;
import com.cloud.pole.recharge.model.CancelTradeRsp;
import com.cloud.pole.recharge.model.CheckIdandCarinfoRsp;
import com.cloud.pole.recharge.model.CheckSmsVerifyCodeOutResp;
import com.cloud.pole.recharge.model.CheckWholeNetTerminalRsp;
import com.cloud.pole.recharge.model.CommonMsg;
import com.cloud.pole.recharge.model.OrderWholeNetTradeProRsp;
import com.cloud.pole.recharge.model.PreOrderForOuterRsp;
import com.cloud.pole.recharge.model.ProductChangeOutRsp;
import com.cloud.pole.recharge.model.QryPayResultRsp;
import com.cloud.pole.recharge.model.QueryDiscntOutResp;
import com.cloud.pole.recharge.model.QueryOutNumInfoRsp;
import com.cloud.pole.recharge.model.QueryWholeNetContractDescRsp;
import com.cloud.pole.recharge.model.QueryWholeNetContractListRsp;
import com.cloud.pole.recharge.model.RespMsg;
import com.cloud.pole.recharge.model.SelTempOccupyResOutRsp;
import com.cloud.pole.recharge.model.SendSmsVerifyCodeOutResp;
import com.cloud.pole.recharge.model.TriggerExtResp;
import com.cloud.pole.recharge.model.UnifiedPayDetailRsp;
import com.cloud.pole.recharge.model.PaySuccFuncRsp;
import com.cloud.pole.recharge.service.RechargeService;
import com.cloud.pole.recharge.util.RSAUtils;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class RechargeServiceImpl implements RechargeService {
	@Resource
	RechargeConstant chargeConstant; 
	
	public void initCommonMsg(CommonMsg commonMsg) {
		commonMsg.setAppId(chargeConstant.getAppId());
		commonMsg.setTradeStaffId(chargeConstant.getTradeStaffId());
		commonMsg.setTradeDepartId(chargeConstant.getTradeDepartId());
		commonMsg.setTradeDepartPasswd(chargeConstant.getTradeDepartPasswd());
		commonMsg.setTradeTerminalId(chargeConstant.getTradeTerminalId());
	}
	
	@Override
	public TriggerExtResp triggerExt(String msisdn) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.IOP_HT_TRIGGEREXT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap();
		map.put("eventCode", RSAUtils.encryptByPublicKey("IOP_HT_TriggerExt", chargeConstant.getPublicKey()));
		Map<String, Object> attr = new HashMap();
		if(!chargeConstant.getEncrypFlag()) {
			attr.put("msisdn", msisdn);
			attr.put("slotIds", chargeConstant.getSlotIds());
		}
		else {
			attr.put("msisdn", RSAUtils.encryptByPublicKey(msisdn, chargeConstant.getPublicKey()));
			attr.put("slotIds", RSAUtils.encryptByPublicKey(chargeConstant.getSlotIds(), chargeConstant.getPublicKey()));	
		}

		map.put("attr", attr);
		String strJson = JSON.toJSONString(map);
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", map);
		
	
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl()+ "?" + commonMsg.getLinkParameter(), strJson);
		attr.clear();
		map.clear();
		log.info("响应报文:{}", strResp);
		RespMsg<TriggerExtResp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<TriggerExtResp>>(){});
		return null;
	}

	@Override
	public QueryDiscntOutResp queryDiscntOut(String serialNumber) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HQ_HNAN_QUERY_DISCNT_OUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		log.info("serialNumber:{}", serialNumber);

		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", serialNumber);
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey(serialNumber, chargeConstant.getPublicKey()));
		}
		//map.put("TRADE_TYPE_CODE", (RSAUtils.encryptByPublicKey(CommonMsg.TRADE_TYPE_CODE_YXHD, chargeConstant.getPublicKey())));
		
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));
		map.clear();
		log.info("响应报文:{}", strResp);

		RespMsg<QueryDiscntOutResp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<QueryDiscntOutResp>>(){});
		//判断成功失败
		if (resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getResult().get(0).getRESULT_CODE();
			if (!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public Boolean sendSmsVerifyCodeOut(String serialNumber, String tradeTypeCode) throws Exception {
		log.info(chargeConstant.getServerUrl());	
		log.info(chargeConstant.getAppId());	

		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HT_HNAN_SEND_SMS_VERIFY_CODE_OUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);

		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", serialNumber);
			map.put("TRADE_TYPE_CODE", tradeTypeCode);

		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey(serialNumber, chargeConstant.getPublicKey()));
			map.put("TRADE_TYPE_CODE", (RSAUtils.encryptByPublicKey(tradeTypeCode, chargeConstant.getPublicKey())));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));

		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));
		map.clear();

		log.info("响应报文:{}", strResp);

		RespMsg<SendSmsVerifyCodeOutResp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<SendSmsVerifyCodeOutResp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getResult().get(0).getRESULT_CODE();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return Boolean.TRUE;
	}

	@Override
	public ProductChangeOutRsp productChangeOut(String serialNumber, String discntCode, String productId, String smsCode) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HT_HNAN_PRODUCT_CHANGE_OUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);

		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", serialNumber);
			map.put("DISCNT_CODE", discntCode);
			map.put("SMS_CODE", smsCode);
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey(serialNumber, chargeConstant.getPublicKey()));
			map.put("DISCNT_CODE", RSAUtils.encryptByPublicKey(discntCode, chargeConstant.getPublicKey()));
			map.put("SMS_CODE", RSAUtils.encryptByPublicKey(smsCode, chargeConstant.getPublicKey()));
		}

		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));

		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));
		map.clear();

		log.info("响应报文:{}", strResp);

		RespMsg<ProductChangeOutRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<ProductChangeOutRsp>>(){});
		//判断成功失败
		if (resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getResult().get(0).getRESULT_CODE();
			if (!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public Boolean checkSmsVerifyCodeOut(String serialNumber, String verifyCode, String tradeTypeCode) 
			throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HT_HNAN_CHECK_SMS_VERIFY_CODE_OUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);

		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", serialNumber);
			map.put("TRADE_TYPE_CODE", tradeTypeCode);
			map.put("VERIFY_CODE", verifyCode);
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey(serialNumber, chargeConstant.getPublicKey()));
			map.put("TRADE_TYPE_CODE", (RSAUtils.encryptByPublicKey(tradeTypeCode, chargeConstant.getPublicKey())));
			map.put("VERIFY_CODE", (RSAUtils.encryptByPublicKey(verifyCode, chargeConstant.getPublicKey())));
		}

		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));

		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));
		map.clear();

		log.info("响应报文:{}", strResp);

		RespMsg<CheckSmsVerifyCodeOutResp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<CheckSmsVerifyCodeOutResp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getResult().get(0).getRESULT_CODE();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return Boolean.TRUE;
	}

	@Override
	public BankRecvFeeOutRsp bankRecvFeeOut(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HT_HNAN_BANK_RECVFEE_OUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_RECVFEEOUT);
		this.initCommonMsg(commonMsg);

		log.info("获取参数：{}", params);
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
			map.put("SMS_CODE", (String)params.get("smsCode"));
			map.put("WRITEOFF_MODE", (String)params.get("writeoffMode"));
			map.put("RECOVER_TAG", (String)params.get("recoverTag"));
			map.put("X_FPAY_FEE", (String)params.get("xFpayFee"));
			map.put("CHARGE_SOURCE_CODE", (String)params.get("chargeSourceCode"));
			map.put("PAY_FEE_MODE_CODE", (String)params.get("payFeeModeCode"));
			map.put("CARRIER_CODE", (String)params.get("carrierCode"));
			map.put("REMOVE_TAG", (String)params.get("removeTag"));
			map.put("CHANNEL_TRADE_ID", (String)params.get("channelTradeId"));
			map.put("CHANNEL_ACCEPT_TIME", (String)params.get("channelAcceptTime"));
			map.put("CHANNEL_ID", (String)params.get("channelId"));
			map.put("TRADE_TYPE_CODE", (String)params.get("tradeTypeCode"));
			map.put("PRODUCT_ID", (String)params.get("productId"));
			map.put("PACKAGE_ID", (String)params.get("packageId"));
			map.put("PARA_CODE1", (String)params.get("paraCode1"));
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
			map.put("SMS_CODE", RSAUtils.encryptByPublicKey((String)params.get("smsCode"), chargeConstant.getPublicKey()));
			map.put("WRITEOFF_MODE", RSAUtils.encryptByPublicKey((String)params.get("writeoffMode"), chargeConstant.getPublicKey()));
			map.put("RECOVER_TAG", RSAUtils.encryptByPublicKey((String)params.get("recoverTag"), chargeConstant.getPublicKey()));
			map.put("X_FPAY_FEE", RSAUtils.encryptByPublicKey((String)params.get("xFpayFee"), chargeConstant.getPublicKey()));
			map.put("CHARGE_SOURCE_CODE", RSAUtils.encryptByPublicKey((String)params.get("chargeSourceCode"), chargeConstant.getPublicKey()));
			map.put("PAY_FEE_MODE_CODE", RSAUtils.encryptByPublicKey((String)params.get("payFeeModeCode"), chargeConstant.getPublicKey()));
			map.put("CARRIER_CODE", RSAUtils.encryptByPublicKey((String)params.get("carrierCode"), chargeConstant.getPublicKey()));
			map.put("REMOVE_TAG", RSAUtils.encryptByPublicKey((String)params.get("removeTag"), chargeConstant.getPublicKey()));
			map.put("CHANNEL_TRADE_ID", RSAUtils.encryptByPublicKey((String)params.get("channelTradeId"), chargeConstant.getPublicKey()));
			map.put("CHANNEL_ACCEPT_TIME", RSAUtils.encryptByPublicKey((String)params.get("channelAcceptTime"), chargeConstant.getPublicKey()));
			map.put("CHANNEL_ID", RSAUtils.encryptByPublicKey((String)params.get("channelId"), chargeConstant.getPublicKey()));
			map.put("TRADE_TYPE_CODE", RSAUtils.encryptByPublicKey((String)params.get("tradeTypeCode"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_ID", RSAUtils.encryptByPublicKey((String)params.get("productId"), chargeConstant.getPublicKey()));
			map.put("PACKAGE_ID", RSAUtils.encryptByPublicKey((String)params.get("packageId"), chargeConstant.getPublicKey()));
			map.put("PARA_CODE1", RSAUtils.encryptByPublicKey((String)params.get("paraCode1"), chargeConstant.getPublicKey()));
			
			map.put("TRADE_FEE", RSAUtils.encryptByPublicKey((String)params.get("trdeFee"), chargeConstant.getPublicKey()));
			map.put("ACCT_ID", RSAUtils.encryptByPublicKey((String)params.get("acctId"), chargeConstant.getPublicKey()));
			map.put("PAYMENT_ID", RSAUtils.encryptByPublicKey((String)params.get("paymentId"), chargeConstant.getPublicKey()));

			
		}
	
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));

		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));
		map.clear();

		log.info("响应报文:{}", strResp);

		RespMsg<BankRecvFeeOutRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<BankRecvFeeOutRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getResult().get(0).getRESULT_CODE();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public String buildSeq() throws Exception {
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_ZF_BUILD_SEQ);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		
		Map<String, Object> map = new HashMap<String, Object>();
		//随便转个值，移动程序接口有BUG
		map.put("msg", "");
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<BuildSeqRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<BuildSeqRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0).getSEQ();
	}

	@Override
	public UnifiedPayDetailRsp unifiedPayDetail(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.TYZF_HT_UNIFIEDPAY_DETAIL);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		log.info("加密前参数:{}", JSON.toJSONString(params));

		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("PEER_ORDER_ID", (String)params.get("peerOrderId"));
			map.put("CRM_ORDER_ID", (String)params.get("crmOrderId"));
			map.put("ORDER_FEE", (String)params.get("orderFee"));
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
			map.put("ORDER_DESC", (String)params.get("orderDesc"));
			map.put("MERCHANT_ID", (String)params.get("merchantId"));
			map.put("OP_ID", (String)params.get("opId"));
			map.put("ORG_ID", (String)params.get("orgId"));
			map.put("COUNTY_ID", (String)params.get("countyId"));
			map.put("REGION_ID", (String)params.get("regionId"));
			map.put("BUSI_TYPE", (String)params.get("busiType"));
			map.put("PAY_WAY", (String)params.get("payWay"));
			map.put("PAY_TYPE", (String)params.get("payType"));
			map.put("REQ_CHANNEL", (String)params.get("reqChannel"));
			map.put("RETURN_URL", (String)params.get("returnUrl"));
		}
		else {
			map.put("PEER_ORDER_ID", RSAUtils.encryptByPublicKey((String)params.get("peerOrderId"), chargeConstant.getPublicKey()));
			map.put("CRM_ORDER_ID", RSAUtils.encryptByPublicKey((String)params.get("crmOrderId"), chargeConstant.getPublicKey()));
			map.put("ORDER_FEE", RSAUtils.encryptByPublicKey((String)params.get("orderFee"), chargeConstant.getPublicKey()));
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
			map.put("ORDER_DESC", RSAUtils.encryptByPublicKey((String)params.get("orderDesc"), chargeConstant.getPublicKey()));
			map.put("MERCHANT_ID", RSAUtils.encryptByPublicKey((String)params.get("merchantId"), chargeConstant.getPublicKey()));
			map.put("OP_ID", RSAUtils.encryptByPublicKey((String)params.get("opId"), chargeConstant.getPublicKey()));
			map.put("ORG_ID", RSAUtils.encryptByPublicKey((String)params.get("orgId"), chargeConstant.getPublicKey()));
			map.put("COUNTY_ID", RSAUtils.encryptByPublicKey((String)params.get("countyId"), chargeConstant.getPublicKey()));
			map.put("REGION_ID", RSAUtils.encryptByPublicKey((String)params.get("regionId"), chargeConstant.getPublicKey()));
			map.put("BUSI_TYPE", RSAUtils.encryptByPublicKey((String)params.get("busiType"), chargeConstant.getPublicKey()));
			map.put("PAY_WAY", RSAUtils.encryptByPublicKey((String)params.get("payWay"), chargeConstant.getPublicKey()));
			map.put("PAY_TYPE", RSAUtils.encryptByPublicKey((String)params.get("payType"), chargeConstant.getPublicKey()));
			map.put("REQ_CHANNEL", RSAUtils.encryptByPublicKey((String)params.get("reqChannel"), chargeConstant.getPublicKey()));
			map.put("RETURN_URL", RSAUtils.encryptByPublicKey((String)params.get("returnUrl"), chargeConstant.getPublicKey()));
		}

		
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<UnifiedPayDetailRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<UnifiedPayDetailRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public CancelTradeRsp cancelTrade(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_ZF_CANCEL_TRADE);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("ORDER_ID", (String)params.get("orderId"));
			map.put("ROUTE_EPARCHY_CODE", (String)params.get("routeEparchyCode"));
			map.put("AMOUNT", (String)params.get("amount"));
			map.put("PAY_MONEY_CODE", (String)params.get("payMoneyCode"));
			map.put("PEER_ORDER_ID", (String)params.get("peerOrderId"));
		}
		else {
			map.put("ORDER_ID", RSAUtils.encryptByPublicKey((String)params.get("orderId"), chargeConstant.getPublicKey()));
			map.put("ROUTE_EPARCHY_CODE", RSAUtils.encryptByPublicKey((String)params.get("routeEparchyCode"), chargeConstant.getPublicKey()));
			map.put("AMOUNT", RSAUtils.encryptByPublicKey((String)params.get("amount"), chargeConstant.getPublicKey()));
			map.put("PAY_MONEY_CODE", RSAUtils.encryptByPublicKey((String)params.get("payMoneyCode"), chargeConstant.getPublicKey()));
			map.put("PEER_ORDER_ID", RSAUtils.encryptByPublicKey((String)params.get("peerOrderId"), chargeConstant.getPublicKey()));
		}

		
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<CancelTradeRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<CancelTradeRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public String paySuccFunc(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_ZF_PAY_SUCC_FUNC);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
			map.put("TRADE_ID", (String)params.get("tradeId"));
			map.put("ROUTE_EPARCHY_CODE", (String)params.get("routeEparchyCode"));
			map.put("AMOUNT", (Integer)params.get("amount"));
			map.put("PAY_MONEY_CODE", (String)params.get("payMoneyCode"));
			map.put("PEER_ORDER_ID", (String)params.get("peerOrderId"));
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
			map.put("TRADE_ID", RSAUtils.encryptByPublicKey((String)params.get("tradeId"), chargeConstant.getPublicKey()));
			map.put("ROUTE_EPARCHY_CODE", RSAUtils.encryptByPublicKey((String)params.get("routeEparchyCode"), chargeConstant.getPublicKey()));
			map.put("AMOUNT", RSAUtils.encryptByPublicKey((String)params.get("amount"), chargeConstant.getPublicKey()));
			map.put("PAY_MONEY_CODE", RSAUtils.encryptByPublicKey((String)params.get("payMoneyCode"), chargeConstant.getPublicKey()));
			map.put("PEER_ORDER_ID", RSAUtils.encryptByPublicKey((String)params.get("peerOrderId"), chargeConstant.getPublicKey()));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<PaySuccFuncRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<PaySuccFuncRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0).getRESULT();
	}

	@Override
	public QryPayResultRsp qryPayResult(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_ZF_QRY_PAY_RESULT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("PEER_ORDER_ID", (String)params.get("peerOrderId"));
			map.put("CREATE_DATE", (String)params.get("createDate"));
			map.put("CHECK_DATE", (String)params.get("checkDate"));
			
		}
		else {
			map.put("PEER_ORDER_ID", RSAUtils.encryptByPublicKey((String)params.get("peerOrderId"), chargeConstant.getPublicKey()));
			map.put("CREATE_DATE", RSAUtils.encryptByPublicKey((String)params.get("createDate"), chargeConstant.getPublicKey()));
			map.put("CHECK_DATE", RSAUtils.encryptByPublicKey((String)params.get("checkDate"), chargeConstant.getPublicKey()));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<QryPayResultRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<QryPayResultRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public PreOrderForOuterRsp preOrderForOuter(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HT_HNAN_PRE_ORDER_FOROUTER);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("REG_NAME", (String)params.get("regName"));
			map.put("CONTACT_NUMBER", (String)params.get("contactNumber"));
			map.put("PSPT_ID", (String)params.get("psptId"));
			map.put("ADDRESS", (String)params.get("address"));
			map.put("CITY", (String)params.get("city"));
			map.put("COUNTY", (String)params.get("county"));
			map.put("DISCNT_CODE", (String)params.get("discntCode"));
			map.put("PARAM_CODE", (String)params.get("paramCode"));
			map.put("OUTER_SERIAL_NUMBER", (String)params.get("outerSerialNumber"));
			map.put("CREATE_TIME", (String)params.get("createTime"));
			map.put("STAFF_ID", (String)params.get("staffId"));
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
		}
		else {
			map.put("REG_NAME", RSAUtils.encryptByPublicKey((String)params.get("regName"), chargeConstant.getPublicKey()));
			map.put("CONTACT_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("contactNumber"), chargeConstant.getPublicKey()));
			map.put("PSPT_ID", RSAUtils.encryptByPublicKey((String)params.get("psptId"), chargeConstant.getPublicKey()));
			map.put("ADDRESS", RSAUtils.encryptByPublicKey((String)params.get("address"), chargeConstant.getPublicKey()));
			map.put("CITY", RSAUtils.encryptByPublicKey((String)params.get("city"), chargeConstant.getPublicKey()));
			map.put("COUNTY", RSAUtils.encryptByPublicKey((String)params.get("county"), chargeConstant.getPublicKey()));
			map.put("DISCNT_CODE", RSAUtils.encryptByPublicKey((String)params.get("discntCode"), chargeConstant.getPublicKey()));
			map.put("PARAM_CODE", RSAUtils.encryptByPublicKey((String)params.get("paramCode"), chargeConstant.getPublicKey()));
			map.put("OUTER_SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("outerSerialNumber"), chargeConstant.getPublicKey()));
			map.put("CREATE_TIME", RSAUtils.encryptByPublicKey((String)params.get("createTime"), chargeConstant.getPublicKey()));
			map.put("STAFF_ID", RSAUtils.encryptByPublicKey((String)params.get("staffId"), chargeConstant.getPublicKey()));
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<PreOrderForOuterRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<PreOrderForOuterRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		// 解密
		if(chargeConstant.getEncrypFlag()) {
			for(PreOrderForOuterRsp paramRsp : resp.getResult()) {
				if(paramRsp.getORDER_NO() != null) {
					paramRsp.setORDER_NO(RSAUtils.decryptByPublicKey(paramRsp.getORDER_NO(), chargeConstant.getPublicKey()));
				}
				paramRsp.setRESULT_MESSAGE(RSAUtils.decryptByPublicKey(paramRsp.getRESULT_MESSAGE(), chargeConstant.getPublicKey()));
				paramRsp.setRESULT_CODE(RSAUtils.decryptByPublicKey(paramRsp.getRESULT_CODE(), chargeConstant.getPublicKey()));

			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public Boolean checkIdandCarinfo(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HQ_HNAN_CHECK_IDANDCARINFO);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("PSPT_ID", (String)params.get("psptId"));
			map.put("CUST_NAME", (String)params.get("custName"));
		}
		else {
			map.put("PSPT_ID", RSAUtils.encryptByPublicKey((String)params.get("psptId"), chargeConstant.getPublicKey()));
			map.put("CUST_NAME", RSAUtils.encryptByPublicKey((String)params.get("custName"), chargeConstant.getPublicKey()));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<CheckIdandCarinfoRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<CheckIdandCarinfoRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return Boolean.TRUE;
	}
	
	@Override
	public QueryOutNumInfoRsp queryOutNumInfo(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HQ_HNAN_QUERY_OUT_NUM_INFO);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SN_EPARCHY_CODE", (String)params.get("snEparchyCode"));
			map.put("SN_CITY_CODE", (String)params.get("snCityCode"));
		}
		else {
			map.put("SN_EPARCHY_CODE", RSAUtils.encryptByPublicKey((String)params.get("snEparchyCode"), chargeConstant.getPublicKey()));
			map.put("SN_CITY_CODE", RSAUtils.encryptByPublicKey((String)params.get("snCityCode"), chargeConstant.getPublicKey()));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
//		String url = "http://111.8.20.250:19001/oppf?method=DQ_HQ_HNAN_checkIdandCarinfo&format=json&appId=502047&status=1&timestamp=20200330103301092&PROVINCE_CODE=HNAN&TRADE_DEPART_PASSWD=ai1234&TRADE_STAFF_ID=ITFPCMAL&TRADE_EPARCHY_CODE=0731&TRADE_CITY_CODE=INTF&TRADE_DEPART_ID=C0ZZC&IN_MODE_CODE=3&ROUTE_EPARCHY_CODE=0731&TRADE_TERMINAL_ID=120.27.24.201&flowdId=4844048";
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

//		String strResp = HttpClientUtils.doPostJson(url, JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<QueryOutNumInfoRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<QueryOutNumInfoRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public SelTempOccupyResOutRsp selTempOccupyResOut(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HT_HNAN_SEL_TEMP_OCCUPY_RESOUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("OCCUPY_TYPE_CODE", (String)params.get("occupyTypeCode"));
			map.put("RES_NO", (String)params.get("resNo"));
			map.put("RES_TYPE_CODE", (String)params.get("resTypeCode"));
		}
		else {
			map.put("OCCUPY_TYPE_CODE", RSAUtils.encryptByPublicKey((String)params.get("occupyTypeCode"), chargeConstant.getPublicKey()));
			map.put("RES_NO", RSAUtils.encryptByPublicKey((String)params.get("resNo"), chargeConstant.getPublicKey()));
			map.put("RES_TYPE_CODE", RSAUtils.encryptByPublicKey((String)params.get("resTypeCode"), chargeConstant.getPublicKey()));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<SelTempOccupyResOutRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<SelTempOccupyResOutRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public QueryWholeNetContractListRsp wholeNetListOut(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HQ_HNAN_WHOLENETLISTOUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
			map.put("PRODUCT_TYPE_CODE", (String)params.get("productTypeCode"));
			
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_TYPE_CODE", RSAUtils.encryptByPublicKey((String)params.get("productTypeCode"), chargeConstant.getPublicKey()));
			
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<QueryWholeNetContractListRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<QueryWholeNetContractListRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public QueryWholeNetContractDescRsp wholeNetDescOut(Map<String, Object> params) throws Exception {
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HQ_HNAN_WHOLENETDESCOUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
			map.put("PRODUCT_TYPE_CODE", (String)params.get("productTypeCode"));
			map.put("PRODUCT_ID", (String)params.get("productId"));
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_TYPE_CODE", RSAUtils.encryptByPublicKey((String)params.get("productTypeCode"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_ID", RSAUtils.encryptByPublicKey((String)params.get("productId"), chargeConstant.getPublicKey()));
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<QueryWholeNetContractDescRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<QueryWholeNetContractDescRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public CheckWholeNetTerminalRsp chkWholeNetTerminalOut(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HQ_HNAN_CHKWHOLENETTERMINALOUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
			map.put("PRODUCT_TYPE_CODE", (String)params.get("productTypeCode"));
			map.put("PRODUCT_ID", (String)params.get("productId"));
			map.put("RES_TYPE", (String)params.get("resType"));
			map.put("RES_CODE", (String)params.get("resCode"));
			
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_TYPE_CODE", RSAUtils.encryptByPublicKey((String)params.get("productTypeCode"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_ID", RSAUtils.encryptByPublicKey((String)params.get("productId"), chargeConstant.getPublicKey()));
			map.put("RES_TYPE", RSAUtils.encryptByPublicKey((String)params.get("resType"), chargeConstant.getPublicKey()));
			map.put("RES_CODE", RSAUtils.encryptByPublicKey((String)params.get("resCode"), chargeConstant.getPublicKey()));	
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<CheckWholeNetTerminalRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<CheckWholeNetTerminalRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}

	@Override
	public OrderWholeNetTradeProRsp orderWholeNetTradeOut(Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		CommonMsg commonMsg = new CommonMsg(CommonMsg.DQ_HT_HNAN_ORDERWHOLENETTRADEOUT);
		commonMsg.setFlowdId(OrderNoUtils.getOrderNo());
		commonMsg.setInModeCode(CommonMsg.IN_MODE_CODE_ELSE);
		this.initCommonMsg(commonMsg);
		
		log.info("参数:{}", JSON.toJSONString(params));

		Map<String, Object> map = new HashMap<String, Object>();
		if(!chargeConstant.getEncrypFlag()) {
			map.put("SERIAL_NUMBER", (String)params.get("serialNumber"));
			map.put("PRODUCT_TYPE_CODE", (String)params.get("productTypeCode"));
			
			map.put("PRODUCT_ID", (String)params.get("productId"));
			map.put("MAIN_RES_CODE", (String)params.get("mainResCode"));
			map.put("MAIN_DEVICE_MODEL_CODE", (String)params.get("mainDeviceModelCode"));
			map.put("MAIN_DEVICE_MODEL", (String)params.get("mainDeviceModel"));
//			map.put("MAIN_BIND_MEMBER", (String)params.get("mainBindMember"));
		
			map.put("MAIN_RES_TYPE", (String)params.get("mainResType"));
			map.put("VOICE_PRODUCT_ID", (String)params.get("voiceProductId"));
			map.put("VOICE_DISC_CODE", (String)params.get("voiceDiscCode"));
//			map.put("PRE_TYPE", (String)params.get("preType"));
			
			map.put("SMS_CODE", (String)params.get("smsCode"));
		}
		else {
			map.put("SERIAL_NUMBER", RSAUtils.encryptByPublicKey((String)params.get("serialNumber"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_TYPE_CODE", RSAUtils.encryptByPublicKey((String)params.get("productTypeCode"), chargeConstant.getPublicKey()));
			map.put("PRODUCT_ID", RSAUtils.encryptByPublicKey((String)params.get("productId"), chargeConstant.getPublicKey()));
			map.put("MAIN_RES_CODE", RSAUtils.encryptByPublicKey((String)params.get("mainResCode"), chargeConstant.getPublicKey()));
			map.put("MAIN_DEVICE_MODEL_CODE", RSAUtils.encryptByPublicKey((String)params.get("mainDeviceModelCode"), chargeConstant.getPublicKey()));
			map.put("MAIN_DEVICE_MODEL", RSAUtils.encryptByPublicKey((String)params.get("mainDeviceModel"), chargeConstant.getPublicKey()));
			map.put("MAIN_BIND_MEMBER", RSAUtils.encryptByPublicKey((String)params.get("mainBindMember"), chargeConstant.getPublicKey()));
			map.put("MAIN_RES_TYPE", RSAUtils.encryptByPublicKey((String)params.get("mainResType"), chargeConstant.getPublicKey()));
			map.put("VOICE_PRODUCT_ID", RSAUtils.encryptByPublicKey((String)params.get("voiceProductId"), chargeConstant.getPublicKey()));
			map.put("VOICE_DISC_CODE", RSAUtils.encryptByPublicKey((String)params.get("voiceDiscCode"), chargeConstant.getPublicKey()));
			map.put("PRE_TYPE", RSAUtils.encryptByPublicKey((String)params.get("preType"), chargeConstant.getPublicKey()));
			map.put("SMS_CODE", RSAUtils.encryptByPublicKey((String)params.get("smsCode"), chargeConstant.getPublicKey()));
		
			
		}
		log.info("请求地址:{}", chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter());
		log.info("请求json:{}", JSON.toJSONString(map));
		
		String strResp = HttpClientUtils.doPostJson(chargeConstant.getServerUrl() + "?" + commonMsg.getLinkParameter(), JSON.toJSONString(map));

		log.info("响应报文:{}", strResp);

		RespMsg<OrderWholeNetTradeProRsp> resp = JSONObject.parseObject(strResp, new TypeReference<RespMsg<OrderWholeNetTradeProRsp>>(){});
		//判断成功失败
		if(resp != null && resp.getResult() != null && resp.getResult().size() > 0) {
			String resultCode = resp.getRespCode();
			if(!StringUtils.equals(resultCode, CommonMsg.RESULT_CODE_SUCCEED)) {
				throw new BaseException(CommonConstants.STATUS_ERROR_CODE, resp.getRespDesc());
			}
		}
		return resp.getResult().get(0);
	}
	
	
}
